;;;
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;     http://paracadd.com
;;;	All rights reserved.
;;;
;;;Stamps the drawing and logs the save.
;;;Prior to DEFUN below (COMMAND ".undefine" "save") is required or this DEFUN will not
;;;redefuine QSAVE (COMMAND ".undefine" "save") can be executed from here or anywhere
;;;else as long as it is called before this DEFUN
;;;
(DEFUN c:save (/ fstr)
  (IF initandsdichk NIL (LOAD "initandsdichk" "\nFile INITANDSDICHK.LSP not loaded! "))
  (initandsdichk)
  (SETQ cur_dwgspec (STRCAT (GETVAR "dwgprefix") (GETVAR "dwgname"))
        cur_file    (DOS_FILE cur_dwgspec)
  ) ;_ end of setq
  (COMMAND ".save" "~")
  (IF (EQ (GETVAR "dbmod") 0)
    (PROGN
      (PRINC (STRCAT "\n  "
                     (STRCASE (GETVAR "dwgprefix"))
                     (STRCASE (GETVAR "dwgname"))
                     " saved.\n"
             ) ;_ end of strcat
      ) ;_ end of princ
;;;      (IF log_it NIL (LOAD "log_it" "\nFile LOG_IT.LSP not loaded! "))
;;;      (IF log_it
;;;        (PROGN
;;;          (SETQ actstr "SAVED")
;;;          (log_it);This func may be cause of crashes during startup
;;;        )
;;;      )
      (COMMAND ".SAVE" (STRCAT (GETVAR "dwgprefix")(GETVAR "dwgname")))
      (princ)
    ) ;_ end of PROGN
    (PROGN
      (PRINC (STRCAT "\n  "
                     (STRCASE (GETVAR "dwgprefix"))
                     (STRCASE (GETVAR "dwgname"))
                     " NOT saved!\n"
             ) ;_ end of strcat
      ) ;_ end of princ
      (ALERT (STRCAT (STRCASE (GETVAR "dwgprefix"))
                     (STRCASE (GETVAR "dwgname"))
                     " NOT SAVED!"
             ) ;_ end of STRCAT
      ) ;_ end of ALERT
    ) ;_ end of PROGN
  ) ;_ end of if
  (SETQ post_dwgspec (STRCAT (GETVAR "dwgprefix") (GETVAR "dwgname"))
        post_file    (DOS_FILE post_dwgspec)
  ) ;_ end of setq
  (IF (EQUAL cur_file post_file)
    (PRINC "\nNothing Changed!")
    (PROGN
      (SETQ fstr "  Saved.................:  ")
      (IF c:cstmp
        nil
        (LOAD "cstmp")
      ) ;_ end of if
      (IF c:lbl
        nil
        (LOAD "lbl")
      ) ;_ end of if
      (SETQ cur_vp (GETVAR "cvport"))
      (IF (AND (EQ (GETVAR "tilemode") 0) (/= cur_vp 1))
        (COMMAND ".pspace")
      ) ;_ end of if
      (IF dlog NIL (LOAD "dlog" "\nFile DLOG.LSP not loaded! "))
      (IF dlog
        (dlog)
      )
      (IF
        (OR
          (IF (NOT (WCMATCH (GETVAR "dwgname") "*\\*"))
            (EQ "X"
                (SUBSTR (GETVAR "dwgname")
                        6
                        1
                ) ;_ end of substr
            ) ;_ end of eq
            (IF (NOT (WCMATCH (GETVAR "dwgname") "*.dwg"))
              (AND
                (EQ "X"
                    (STRCASE (SUBSTR (GETVAR "dwgname")
                                     (- (STRLEN (GETVAR "dwgname")) 2)
                                     1
                             ) ;_ end of substr
                    ) ;_ end of strcase
                ) ;_ end of eq
                (EQ "\\"
                    (STRCASE (SUBSTR (GETVAR "dwgname")
                                     (- (STRLEN (GETVAR "dwgname")) 8)
                                     1
                             ) ;_ end of substr
                    ) ;_ end of strcase
                ) ;_ end of eq
              ) ;_ end of and
              (AND
                (EQ "X"
                    (STRCASE (SUBSTR (GETVAR "dwgname")
                                     (- (STRLEN (GETVAR "dwgname")) 6)
                                     1
                             ) ;_ end of substr
                    ) ;_ end of strcase
                ) ;_ end of eq
                (EQ "\\"
                    (STRCASE (SUBSTR (GETVAR "dwgname")
                                     (- (STRLEN (GETVAR "dwgname")) 12)
                                     1
                             ) ;_ end of substr
                    ) ;_ end of strcase
                ) ;_ end of eq
              ) ;_ end of and
            ) ;_ end of if
          ) ;_ end of if
          (EQ "XBASE.DWG" (STRCASE (GETVAR "dwgname")))
          (EQ (GETVAR "TILEMODE") 1)
        ) ;_ end of or
         (PROGN
           (PRINC "\n(substr (getvar \"dwgname\") 6 1)=")
           (PRINC (SUBSTR (GETVAR "dwgname") 6 1))
         ) ;_ end of progn
         (PROGN
           (IF (OR (EQ (GETVAR "tilemode") 1)
                   (AND (>= (STRLEN (GETVAR "dwgname")) 8)
                        (EQ (STRCASE (SUBSTR (GETVAR "dwgname") 6 1)) "X")
                   ) ;_ end of and
                   (WCMATCH (STRCAT (GETVAR "loginname")) "JASBILL")
                   (WCMATCH (STRCAT (GETVAR "loginname")) "JFISHER")
                   (WCMATCH (STRCAT (GETVAR "loginname")) "JPADGETT")
               ) ;_ end of or
             nil
             (IF (EQUAL (GETVAR "limmax") (LIST 14.0 8.5) 3)
               (c:cstmp)
               (c:lbl)
             ) ;_ end of IF
           ) ;_ end of if
           (IF (EQ (SUBSTR (GETVAR "dwgprefix") 1 5) "\\10208\\21620")
             (PROGN
               (IF lvndx
                 nil
                 (LOAD "lvndx")
               ) ;_ end of if
               (lvndx)
             ) ;_ end of progn
             (PROGN
               (IF corpndx
                 nil
                 (LOAD "corpndx")
               ) ;_ end of if
               (corpndx)
             ) ;_ end of progn
           ) ;_ end of if
         ) ;_ end of progn
      ) ;_ end of if
      (IF (AND (EQ (GETVAR "tilemode") 0) (/= cur_vp 1))
        (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-true)
;;;        (COMMAND "_.mspace")
      ) ;_ end of if
      (IF align_lst
        (PROGN
          (SETQ num (LOAD_DIALOG "gpdgn"))
          (gate_dlg)
        ) ;_ end of progn
      ) ;_ end of if
      (IF c:backup NIL (LOAD "backup" "\nFile BACKUP.LSP not loaded! "))
      (IF c:backup
        (c:backup)
      )
    ) ;_ end of progn
  ) ;_ end of if
  (PRINC)
) ;_ end of defun
